<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="人员姓名" prop="personName">
        <el-input
          v-model="queryParams.personName"
          placeholder="请输入人员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="personIdno">
        <el-input
          v-model="queryParams.personIdno"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="personSex">
        <el-select v-model="queryParams.personSex" placeholder="请选择性别">
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="婚否" prop="personMarried">
        <el-select v-model="queryParams.personMarried" placeholder="请选择婚否">
        <el-option
          v-for="dict in dict.type.sys_marriage"
          :key="dict.value"
          :label="dict.label"
          :value="dict.value"
        ></el-option>
      </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="personAge">
        <el-input
          v-model="queryParams.personAge"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="personBirthday">
        <el-date-picker clearable
          v-model="queryParams.personBirthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="套餐名称" prop="solutionId">
        <el-select v-model="queryParams.solutionId" placeholder="请选择套餐">
          <el-option
            v-for="item in basepackageList"
            :key="item.id"
            :label="item.packagename"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="联系方式" prop="personPhoneno">
        <el-input
          v-model="queryParams.personPhoneno"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约日期" prop="appointdate">
        <el-date-picker clearable
          v-model="queryParams.appointdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="人员单位" prop="personCompanyid">
        <el-select v-model="queryParams.personCompanyid" placeholder="请选择人员单位">
        <el-option
          v-for="item in companyList"
          :key="item.id"
          :label="item.companyname"
          :value="item.id">
        </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预约渠道" prop="personChannel">
        <el-select v-model="queryParams.personChannel" placeholder="请选择预约渠道">
          <el-option
            v-for="dict in dict.type.dime_channel_type"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预约类型" prop="physicalType">
        <el-select v-model="queryParams.physicalType" placeholder="请选择预约类型" style="width: 100%">
          <el-option
            v-for="dict in dict.type.dime_appointment_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预约状态" prop="personStatus">
        <el-select v-model="queryParams.personStatus" placeholder="请选择预约类型" style="width: 100%">
          <el-option
            v-for="dict in dict.type.sys_appointment_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['appointment:appointment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['appointment:appointment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['appointment:appointment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['appointment:appointment:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['appointment:appointment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appointmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="人员姓名" align="center" prop="personName" />
      <el-table-column label="性别" align="center" prop="personSex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.personSex"/>
        </template>
      </el-table-column>
      <el-table-column label="身份证" align="center" prop="personIdno" />
      <el-table-column label="婚否" align="center" prop="personMarried">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_marriage" :value="scope.row.personMarried"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="personAge" />
      <el-table-column label="出生日期" align="center" prop="personBirthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.personBirthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="套餐名称" align="center" prop="solutionName" />
      <el-table-column label="联系方式" align="center" prop="personPhoneno" />
      <el-table-column label="预约日期" align="center" prop="appointdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.appointdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单位名称" align="center" prop="personCompanyname" />
      <el-table-column label="预约渠道" align="center" prop="personChannel">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.dime_channel_type" :value="scope.row.personChannel"/>
      </template>
      </el-table-column>
      <el-table-column label="预约类型" align="center" prop="physicalType">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.dime_appointment_type" :value="scope.row.physicalType"/>
      </template>
      </el-table-column>
      <el-table-column label="预约状态" align="center" prop="personStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_appointment_status" :value="scope.row.personStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="原价" align="center" prop="originalPrice" />
      <el-table-column label="协议价" align="center" prop="amount" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['appointment:appointment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['appointment:appointment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预约人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :fullscreen="true">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="人员姓名" prop="personName">
              <el-input v-model="form.personName" placeholder="请输入人员姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证" prop="personIdno">
              <el-input v-model="form.personIdno" placeholder="请输入身份证" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="性别" prop="personSex">
              <el-select v-model="form.personSex" placeholder="请选择性别" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_user_sex"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="婚否" prop="personMarried">
              <el-select v-model="form.personMarried" placeholder="请选择婚否" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_marriage"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="年龄" prop="personAge">
              <el-input v-model="form.personAge" placeholder="请输入年龄" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期" prop="personBirthday">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.personBirthday"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择出生日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="联系方式" prop="personPhoneno">
              <el-input v-model="form.personPhoneno" placeholder="请输入联系方式" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人员单位" prop="personCompanyid">
              <el-select v-model="form.personCompanyid" placeholder="请选择人员单位" style="width: 100%" @change="changeCompany">
                <el-option
                  v-for="item in companyList"
                  :key="item.id"
                  :label="item.companyname"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="预约日期" prop="appointdate">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.appointdate"
                              type="date"
                              :picker-options="pickerOptions"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择预约日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预约类型" prop="physicalType">
              <el-select v-model="form.physicalType" placeholder="请选择预约类型" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.dime_appointment_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="预约状态" prop="personStatus">
              <el-select v-model="form.personStatus" placeholder="请选择预约类型" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.sys_appointment_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预约渠道" prop="personChannel">
              <el-select v-model="form.personChannel" placeholder="请选择预约渠道" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.dime_channel_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注"/>
            </el-form-item>
        </el-row>
        <div class="addition">
          套餐和加项信息
          <el-button type="primary" style="margin-left:10px" @click="choosePackage">选择套餐</el-button>
          <el-button type="primary" plain style="margin-left:10px" @click="chooseCombAddition">加/减项</el-button>
        </div>
        <div class="priceInfo">
          <div class="priceInfoItem">
            <div>挂账（未支付）：<span>￥0.00</span></div>
            <div>挂账（已支付）：<span>￥0.00</span></div>
            <div>自费（已支付）：<span>￥0.00</span></div>
          </div>
          <div class="priceInfoItem">
            <div>挂账（未支付）：<span>￥0.00</span></div>
            <div>挂账（已支付）：<span>￥0.00</span></div>
            <div>自费（已支付）：<span>￥0.00</span></div>
          </div>
        </div>
        <el-table :data="choosedpackageList" @expand-change="handleExpandChange">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-table :data="props.row.pagecomblist" style="width: 50%;margin-left:50px" stripe border v-loading="!props.row.loadDetails">
                <el-table-column type="index" width="50" align="center"></el-table-column>
                <el-table-column label="组合编码" align="center" prop="combcode" />
                <el-table-column label="组合名称" align="center" prop="combname" />
                <el-table-column label="组合类型" align="center" prop="combtype">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_comb_type" :value="scope.row.combtype"/>
                  </template>
                </el-table-column>
                <el-table-column label="适用性别" align="center" prop="applysex">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.applysex"/>
                  </template>
                </el-table-column>
                <el-table-column label="项目价格" align="center" prop="combprice" />
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="检查项目" align="center" prop="packagename" />
          <el-table-column label="类别" align="center" prop="" />
          <el-table-column label="支付状态" align="center" prop="" />
          <el-table-column label="原价" align="center" prop="packageoriginalprice" />
          <el-table-column label="协议价" align="center" prop="packagediscountprice" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          </el-table-column>
        </el-table>
        <div class="additionTitle">门店加项</div>
        <el-table :data="shopAdditionList" :show-header="false" v-if="shopAdditionList&& shopAdditionList.length > 0">
          <el-table-column
            type="index"
            align="center"
            width="50">
          </el-table-column>
          <el-table-column label="检查项目" align="center" prop="combname" />
          <el-table-column label="类别" align="center" prop="" />
          <el-table-column label="支付状态" align="center" prop="" />
          <el-table-column label="原价" align="center" prop="combprice" />
          <el-table-column label="协议价" align="center" prop="packagediscountprice" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 套餐选择弹框 -->
    <el-dialog title="套餐选择" :visible.sync="showPackageList" width="800px" append-to-body>
          <el-input placeholder="请输入套餐名称" v-model="packageInput" style="margin-bottom: 15px;">
            <el-button slot="append" icon="el-icon-search" @click="this.getBasepackageList"></el-button>
          </el-input>
        <el-table v-loading="packageLoading" :data="basepackageListData" @row-click="handlePackageChange" max-height="500">
          <el-table-column
            label="选择项"
            align="center"
            width="60">
            <template slot-scope="scope">
              <el-radio v-model="tableRadio" :label="scope.row.id">&zwnj;</el-radio>
            </template>
          </el-table-column>
          <el-table-column label="套餐名称" align="center" prop="packagename" />
          <el-table-column label="原价" align="center" prop="packageoriginalprice" />
          <el-table-column label="协议价" align="center" prop="packagediscountprice" />
          <el-table-column label="适用性别" align="center" prop="sexenum">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sexenum"/>
            </template>
          </el-table-column>
          <el-table-column label="单位名称" align="center" prop="companyName" />
        </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChoosedPackage">确 定</el-button>
        <el-button @click="showPackageList = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 加减项弹框 -->
    <el-dialog title="加项" :visible.sync="showCombAddition" width="1400px" append-to-body>
      <table-transfer ref="tableTransfer" :list="transferList"></table-transfer>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showCombAddition = false">取 消</el-button>
        <el-button type="primary" @click="confirmCombAddition">确认选择</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppointment, getAppointment, delAppointment, addAppointment, updateAppointment,getPackageInfo } from "@/api/appointment/appointment";
import { listBasecompany} from "@/api/base/basecompany";
import { getToken } from '@/utils/auth'
import { listBasepackage, getBasepackage, getPagecomblist } from '@/api/base/basepackage'
import { listBasecomb } from '@/api/base/basecomb'
import TableTransfer from '@/components/TableTransfer'

export default {
  name: "Appointment",
  components: { TableTransfer },
  dicts: ['sys_marriage', 'sys_user_sex','dime_appointment_type','sys_appointment_status','sys_comb_type','dime_channel_type'],
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now();//只可以选择今天过后的日期
        }
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/base/baseitem/importData"
      },
      packageInput: '',
      combInput: '',
      tableRadio: '',
      tableRow: {},
      // 遮罩层
      loading: true,
      //套餐遮罩
      packageLoading: true,
      //显示选择套餐弹框
      showPackageList: false,
      //显示加项弹框
      showCombAddition: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约人员表格数据
      appointmentList: [],
      //人员单位
      companyList: [],
      //已选择的套餐
      choosedpackageList: [],
      //门店加项
      shopAdditionList: [],
      //套餐表格数据
      basepackageListData: [],
      //套餐列表
      basepackageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //体检选项
      basecombList: [],
      //穿梭框列表
      transferList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        personName: null,
        personSex: null,
        personIdno: null,
        personMarried: null,
        personAge: null,
        personBirthday: null,
        solutionId: null,
        solutionName: null,
        personPhoneno: null,
        shopId: null,
        appointdate: null,
        personCompanyid: null,
        personCompanyname: null,
        physicalType: null,
        personChannel: null,
        personStatus: null,
        originalPrice: null,
        amount: null,
        createtime: null,
        updatetime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        personName: [
          { required: true, message: "人员姓名不能为空", trigger: "blur" }
        ],
        personIdno: [
          { required: true, message: "身份证不能为空", trigger: "blur" }
        ],
        personPhoneno: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        personMarried: [
          { required: true, message: "婚否不能为空", trigger: "change" }
        ],
        personBirthday: [
          { required: true, message: "出生日期不能为空", trigger: "change" }
        ],
        appointdate: [
          { required: true, message: "预约日期不能为空", trigger: "change" }
        ],
        personSex: [
          { required: true, message: "适用性别不能为空", trigger: "change" }
        ],
        personCompanyid: [
          { required: true, message: "人员单位不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getCompanyList()
    this.getBasecombList()
    listBasepackage({pageNum: 1,
      pageSize: 100}).then(response => {
      this.basepackageList = response.rows;
    });
  },
  methods: {
    /** 查询预约人员列表 */
    getList() {
      this.loading = true;
      listAppointment(this.queryParams).then(response => {
        this.appointmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handlePackageChange(currentRow){
      this.tableRadio = currentRow.id;
      this.tableRow=currentRow
    },
    handleExpandChange(row){
      if(!row.loadDetails) {
        getPagecomblist(row.id).then(response => {
          row.pagecomblist = response.data
          row.loadDetails = true
        });
      }
    },
    submitChoosedPackage(){
      if(this.tableRadio){
        this.choosedpackageList = [this.tableRow];
        this.choosedpackageList.forEach(item => {
          this.$set(item, 'pagecomblist', [])
          this.$set(item, 'loadDetails', false)
        })
        this.showPackageList = false;
      }else{
        return this.$message.warning('请选择套餐')
      }
    },
    choosePackage(){
      if(this.form.personSex&&this.form.personCompanyid){
        this.getBasepackageList()
        this.tableRadio=''
        this.showPackageList=true
      }else{
        return this.$message.warning('请选择性别或人员单位')
      }
    },
    chooseCombAddition() {
      if(this.choosedpackageList.length == 0) {
        this.$message.warning('请选择体检套餐')
        return
      }
      getPagecomblist(this.choosedpackageList[0].id).then(response => {
        this.showCombAddition=true
        this.$nextTick(()=>{
          let list = this.basecombList.concat()
          this.removeAll(list, response.data)
          this.transferList = list
          this.$refs.tableTransfer.setChoosedbasecombList(this.shopAdditionList.concat())
        })
      });
    },
    removeAll(arr, removedArr) {
      removedArr.forEach(item=>{
        const index = arr.findIndex(value => {
          return value['id'] == item['id']
        })
        if(index >= 0) {
          arr.splice(index, 1)
        }
      })
    },
    //确认加项选择
    confirmCombAddition() {
      let choosedList = this.$refs.tableTransfer.getChoosedbasecombList();
      if(choosedList&&choosedList.length>0){
        this.shopAdditionList=choosedList.concat()
        this.showCombAddition = false
      }else{
        return this.$message.warning('请选择检查项目')
      }
    },
    changeCompany(id){
      for(let i = 0; i < this.companyList.length; i++) {
        if(this.companyList[i].id == id) {
          this.form.personCompanyname=this.companyList[i].companyname
        }
      }
    },
    getCompanyList() {
      listBasecompany({pageNum: 1,
        pageSize: 100}).then(response => {
        this.companyList = response.rows;
      });
    },
    getBasecombList(){
      listBasecomb({pageNum: 1,
        pageSize: 100}).then(response => {
        this.basecombList = response.rows;
      });
    },
    getBasepackageList() {
      this.packageLoading = true;
      listBasepackage({pageNum: 1,
        pageSize: 100,sexenum:this.form.personSex,companynameid:this.form.personCompanyid,packagename:this.packageInput}).then(response => {
        this.basepackageListData = response.rows;
        this.packageLoading = false;
      });
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/appointment/appointment/importTemplate', {
      }, `appointment_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        personName: null,
        personSex: null,
        personIdno: null,
        personMarried: null,
        personAge: null,
        personBirthday: null,
        solutionId: null,
        solutionName: null,
        personPhoneno: null,
        shopCode: null,
        appointdate: null,
        personCompanyid: null,
        personCompanyname: null,
        physicalType: null,
        personChannel: null,
        personStatus: "0",
        originalPrice: null,
        amount: null,
        createtime: null,
        updatetime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.choosedpackageList=[];
      this.shopAdditionList=[];
      this.reset();
      this.open = true;
      this.title = "添加预约人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPackageInfo(id).then(response => {
        this.form = response.data.physicalPersons;
        this.shopAdditionList = this.form.physicalCombsdetailList.filter(item=>{
          return item.combType == 1
        })
        this.shopAdditionList.forEach(item=>{
            item.combname=item.combName
            item.combprice=item.originalPrice
          }
        )
        if(response.data.dimeBasepackage) {
          this.choosedpackageList=[response.data.dimeBasepackage];
          this.choosedpackageList.forEach(item => {
            this.$set(item, 'pagecomblist', [])
            this.$set(item, 'loadDetails', false)
          })
        }
        this.open = true;
        this.title = "修改预约人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          if(this.choosedpackageList.length == 0) {
            this.$message.warning('请选择体检套餐')
            return
          }
          //异步操作，要先拿到数据才能下一步，后续操作要么放在then,要么用await
          const res = await getPagecomblist(this.choosedpackageList[0].id)
          this.form.physicalCombsdetailList = []
          //使用...把数组解构放入，否则放入的是数组
          res.data.forEach(item=>{
            item.combType = 0
            item.combNumber = 1
            item.combId=item.id
            item.combName=item.combname
            item.originalPrice=item.combprice
          })
          this.form.physicalCombsdetailList.push(...res.data)
          this.shopAdditionList.forEach(item=>{
            item.combType = 1
            item.combNumber = 1
            item.combId=item.id
            item.combName=item.combname
            item.originalPrice=item.combprice
          })
          this.form.physicalCombsdetailList.push(...this.shopAdditionList)
          this.form.solutionId = this.choosedpackageList[0].id
          this.form.solutionName = this.choosedpackageList[0].packagename
          if (this.form.id != null) {
            updateAppointment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppointment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除预约人员编号为"' + ids + '"的数据项？').then(function() {
        return delAppointment(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/appointment/appointment/export', {
        ...this.queryParams
      }, `appointment_${new Date().getTime()}.xlsx`)
    },
    /** 打开导入表弹窗 */
    openImportTable() {
      this.$refs.import.show();
    },
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.addition{
  padding:10px 16px 16px;
  border-bottom: 1px solid #d2d2d2;
  font-size: 18px;
}
.additionTitle{
  padding: 10px 20px;
  font-size: 14px;
  font-weight: bold;
  color: #1a5fff;
}

.priceInfo{
  margin: 16px 0;
  padding:0 18px;
  .priceInfoItem{
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 6px;
    span{
      color: #db8070;
    }
  }
}
</style>
